import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';

import { useI18n } from '/@/hooks/web/useI18n';
import { defHttp } from '/@/utils/http/axios';
enum Api {
  AllRoleList = '/sys/spaUserRole/allRoleList',
  PageList = '/sys/spaUser/listByPage',
  Add = '/sys/spaUser/add',
  Edit = '/sys/spaUser/edit',
  Delete = '/sys/spaUser/delete?id=',
}
const { t } = useI18n();
//
export const getAllRoleList = (params?: any) => {
  const a = defHttp.get<any>({ url: Api.AllRoleList, params });
  console.log(a);
  return a;
};
//
export const getListByPage = (params?: any) => defHttp.get<any>({ url: Api.PageList, params });
//
export const addSpaUser = (params?: any) => {
  return defHttp.post<any>({ url: Api.Add, params });
};

export const editSpaUser = (params?: any) => {
  return defHttp.put<any>({ url: Api.Edit, params });
};

/**
 * 删除字典
 */
export const deleteSpaUser = (id, handleSuccess) => {
  return defHttp.delete({ url: Api.Delete + id }).then(() => {
    handleSuccess();
  });
};

export const columns: BasicColumn[] = [
  {
    title: '姓名',
    dataIndex: 'realName',
    width: 200,
  },
  {
    title: '用户名',
    dataIndex: 'usrName',
    width: 200,
  },

  {
    title: '邮箱',
    dataIndex: 'usrEmail',
    width: 200,
  },
  {
    title: '手机',
    dataIndex: 'mobile',
    width: 200,
  },
  {
    title: '角色',
    dataIndex: 'roleId',
    width: 200,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'realName',
    label: '姓名',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'usrName',
    label: '用户名',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'usrEmail',
    label: '邮箱',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'mobile',
    label: '手机',
    component: 'Input',
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '唯一标识',
    required: false,
    component: 'Input',
    show: false,
  },
  {
    field: 'realName',
    label: '姓名',
    required: true,
    component: 'Input',
  },
  {
    field: 'usrName',
    label: '用户名',
    required: true,
    component: 'Input',
  },

  {
    field: 'usrEmail',
    label: '邮箱',
    required: false,
    component: 'Input',
  },
  {
    field: 'mobile',
    label: '手机',
    required: false,
    component: 'Input',
  },
  {
    field: 'roleId',
    label: '角色',
    required: false,
    component: 'ApiSelect',
    componentProps: {
      //mode: 'multiple',
      api: getAllRoleList,
      // numberToString: true,
      labelField: 'roleName',
      valueField: 'id',
    },
  },
];
